package com.ssy.lingxi.order.serviceimpl.platform;

import com.ssy.lingxi.common.constant.basic.EnableDisableStatus;
import com.ssy.lingxi.common.constant.basic.PlatformRuleTypeEnum;
import com.ssy.lingxi.common.constant.settle.SettlementTypeEnum;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.api.model.vo.response.PlatformSettlementTypeVO;
import com.ssy.lingxi.order.repository.BaseOrderRuleRepository;
import com.ssy.lingxi.order.service.platform.IPlatformSettlementTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 平台后台 - 结算支付方式相关接口实现类
 * @author 彭冬冬
 * @version 2.0.0
 * @date 2021-12-9
 */
@Service
public class PlatformSettlementTypeServiceImpl implements IPlatformSettlementTypeService {

    @Resource
    private BaseOrderRuleRepository baseOrderRuleRepository;

    @Override
    public Wrapper<List<PlatformSettlementTypeVO>> findSettlementTypeByEnable() {
        List<PlatformSettlementTypeVO> data = baseOrderRuleRepository.findByRuleTypeAndStatus(PlatformRuleTypeEnum.SETTLEMENT_TYPE.getCode(), EnableDisableStatus.ENABLE.getCode()).stream().map(map -> new PlatformSettlementTypeVO(map.getMethodCode(), SettlementTypeEnum.getName(map.getMethodCode()))).collect(Collectors.toList());
        return Wrapper.success(data);
    }

    @Override
    public Wrapper<List<PlatformSettlementTypeVO>> findSettlementCategoryByEnable() {
        List<PlatformSettlementTypeVO> data = baseOrderRuleRepository.findByRuleTypeAndStatus(PlatformRuleTypeEnum.SETTLEMENT.getCode(), EnableDisableStatus.ENABLE.getCode()).stream().map(map -> new PlatformSettlementTypeVO(map.getMethodCode(), map.getMethodName())).collect(Collectors.toList());
        return Wrapper.success(data);
    }

}
